<template>
  <common-page title="行政许可事项办理">
    <avue-crud
      ref="crud"
      v-model="form"
      class="crud-table"
      :option="tableOption"
      :data="list"
      :page.sync="page"
      :search.sync="searchForm"
      :table-loading="loading"
      :header-cell-class-name="() => 'crud-table-head'"
      :cell-class-name="() => 'crud-cell'"
      @search-change="searchChange"
      @refresh-change="getList()"
      @hook:mounted="$ele.tableMount($refs.crud)"
      @hook:beforeDestroy="$ele.tableDestroy($refs.crud)"
      @current-change="currentChange"
      @size-change="handleSizeChange"
    >
      <template #menuLeft>
        <el-button type="primary" @click="handleExport" :loading="isUpload">事项受理</el-button>
      </template>
      <template #searchMenu="{ size }">
        <el-button type="primary" :size="size" @click="searchChange">查 询 </el-button>
        <el-button type="primary" plain :size="size" @click="resetForm">重 置 </el-button>
      </template>
      <template #menu>
        <el-button type="text" @click="handle5()">受理</el-button>
        <el-button type="text" @click="handle()">监督检查</el-button>
        <el-button type="text" @click="handle1()">补充</el-button>
        <el-button type="text" @click="handle2()">终止</el-button>
        <el-button type="text" @click="handle3()">归档</el-button>
        <el-button type="text" @click="handle4()">归档查看</el-button>
        <el-button type="text" @click="handle6()">操作记录</el-button>
      </template>
    </avue-crud>
    <!-- dialog -->
    <el-dialog title="资料补充" :visible.sync="dialogVisible" width="30%" custom-class="crud-dialog" :before-close="() => (dialogVisible = false)">
      <el-upload
        class="upload-demo"
        action="https://jsonplaceholder.typicode.com/posts/"
        :on-remove="handleRemove"
        :before-remove="beforeRemove"
        multiple
        :limit="3"
        :on-exceed="handleExceed"
        :file-list="fileList"
      >
        <el-button size="small" type="primary">点击上传</el-button>
        <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div> -->
      </el-upload>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- look -->
    <el-dialog title="查看" :visible.sync="view1" width="30%" custom-class="crud-dialog" :before-close="() => (view1 = false)">
      <avue-crud
        ref="crud"
        v-model="form"
        class="crud-table"
        :option="options1"
        :data="list1"
        :page.sync="page"
        :search.sync="searchForm"
        :table-loading="loading"
        :header-cell-class-name="() => 'crud-table-head'"
        :cell-class-name="() => 'crud-cell'"
        @search-change="searchChange"
        @refresh-change="getList()"
        @hook:mounted="$ele.tableMount($refs.crud)"
        @hook:beforeDestroy="$ele.tableDestroy($refs.crud)"
        @current-change="currentChange"
        @size-change="handleSizeChange"
      >
      </avue-crud>
      <span slot="footer" class="dialog-footer"> </span>
    </el-dialog>
    <!-- 记录 -->
    <el-dialog title="操作记录" :visible.sync="view2" width="30%" custom-class="crud-dialog" :before-close="() => (view2 = false)">
      <avue-crud
        ref="crud"
        v-model="form"
        class="crud-table"
        :option="options2"
        :data="list2"
        :page.sync="page"
        :search.sync="searchForm"
        :table-loading="loading"
        :header-cell-class-name="() => 'crud-table-head'"
        :cell-class-name="() => 'crud-cell'"
        @search-change="searchChange"
        @refresh-change="getList()"
        @hook:mounted="$ele.tableMount($refs.crud)"
        @hook:beforeDestroy="$ele.tableDestroy($refs.crud)"
        @current-change="currentChange"
        @size-change="handleSizeChange"
      >
      </avue-crud>
      <span slot="footer" class="dialog-footer"> </span>
    </el-dialog>
    <!-- 0 -->
    <el-dialog title="监督检查" :visible.sync="view3" width="30%" custom-class="crud-dialog" :before-close="() => (view3 = false)">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="检查机构">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="检查人">
          <el-select v-model="form.region" placeholder="检查人">
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="检查时间">
          <el-col :span="11">
            <el-date-picker type="date" placeholder="选择日期" v-model="form.date1" style="width: 100%"></el-date-picker>
          </el-col>
        </el-form-item>
        <el-form-item label="检查信息">
          <el-input type="textarea" v-model="form.desc"></el-input>
        </el-form-item>
        <el-form-item label="是否通过">
          <el-switch v-model="form.delivery"></el-switch>
        </el-form-item>
        <el-form-item label="问题清单">
          <el-input type="textarea" v-model="form.desc"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </common-page>
</template>

<script>
import { tableOption, options1, options2 } from './tableOption'
import { getMattersPage } from '@/api/matters'
import fileDownload from 'js-file-download'
export default {
  data() {
    return {
      isUpload: false,
      view1: false,
      view2: false,
      view3: false,
      form: {},
      action: 'https://api.avuejs.com/imgupload',
      propsHttp: {},
      fileList: [],
      searchForm: {},
      dialogVisible: false,
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      list: [],
      list1: [{ p1: '2024-5-7', p2: '发起来', p3: '归档了' }],
      list2: [
        { p1: '操作人', p2: '受理', p3: '2024-5-7' },
        { p1: '操作人', p2: '材料补充', p3: '2024-6-7' },
        { p1: '操作人', p2: '归档', p3: '2024-8-7' }
      ],
      loading: true,
      form: {},
      shipTypeArr: [], // 船舶类型
      shipSTypeArr: [],
      homePortArr: [], // 船籍港
      registArr: [] // 登记机构
    }
  },
  computed: {
    tableOption() {
      return tableOption.call(this)
    },
    options1() {
      return options1.call(this)
    },
    options2() {
      return options2.call(this)
    },
    documentHeight() {
      return this.$store.state.app.documentClientHeight
    }
  },
  created() {
    this.getList()
  },
  methods: {
    resetForm() {
      this.$refs.crud.searchReset()
      this.page.currentPage = 1
      this.getList()
    },

    getList() {
      this.loading = true
      getMattersPage({
        ...this.searchForm,
        pageNumber: this.page.currentPage,
        pageSize: this.page.pageSize
      })
        .then((res) => {
          this.list = res.result.records
          this.page.total = res.result.total
        })
        .catch((err) => {})
        .finally(() => {
          this.loading = false
          this.$refs.crud?.doLayout()
        })
    },
    currentChange(val) {
      this.page.currentPage = val
      this.getList()
      this.$refs.curd?.doLayout()
    },
    handleSizeChange(val) {
      this.page.pageSize = val
      this.getList()
      this.$refs.curd.doLayout()
    },
    searchChange(form, done) {
      this.page.currentPage = 1
      this.getList()
      done && done()
    },
    // 船舶类型
    async getShipArr() {
      let { result } = await getDict('ship_type')
      this.shipTypeArr = result
      let { result: s } = await getDict('ship_large_type')
      this.shipSTypeArr = s
    },
    // 船籍港
    async getHomePortArr() {
      let { result } = await getDictByHome()
      this.homePortArr = result
    },
    // 登记机构
    async getRegistArr() {
      let { result } = await getDictByRegist()
      this.registArr = this.getPortData(result)
    },
    getPortData(data) {
      for (var i = 0; i < data.length; i++) {
        if (data[i].children) {
          if (data[i].children.length < 1) {
            data[i].children = undefined
          } else {
            this.getPortData(data[i].children)
          }
        }
      }
      return data
    },
    // 导出
    async handleExport() {
      this.isUpload = true
      this.axios({
        url: '/api/supervise/tenant/export',
        methods: 'get',
        responseType: 'blob',
        params: this.searchForm,
        headers: {
          Authorization: `bearer ${window.$auth.getToken()}`
        }
      })
        .then((res) => {
          this.isUpload = false
          fileDownload(res.data, `监管船舶信息表.xls`)
        })
        .catch(() => {
          this.isUpload = false
        })
    },
    handleExceed() {},
    beforeRemove() {},
    handleRemove() {},
    handle6() {
      this.view2 = true
    },
    handle5() {
      this.$confirm('确认受理?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.$message({
            type: 'success',
            message: '成功!'
          })
        })
        .catch(() => {})
    },
    handle1() {
      this.dialogVisible = true
    },
    handle2() {
      this.$confirm('事项确认终止?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.$message({
            type: 'success',
            message: '终止成功!'
          })
        })
        .catch(() => {})
    },
    handle3() {
      this.$confirm('事项确认归档?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.$message({
            type: 'success',
            message: '归档成功!'
          })
        })
        .catch(() => {})
    },
    handle4() {
      this.view1 = true
    },
    handle() {
      this.view3 = true
    }
  }
}
</script>
<style scoped lang="scss"></style>
